package com.haven.login.dao.hibernate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManagerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.support.JpaDaoSupport;
import org.springframework.stereotype.Repository;

import com.haven.login.dao.LoginDao;
import com.haven.login.model.Account;

@Repository(value="loginDaoHibernate")
public class LoginDaoHibernate extends JpaDaoSupport implements LoginDao {

	@Autowired
	EntityManagerFactory entityManagerFactory;
	
	//EntityManager entityManager;
    
	@PostConstruct
	 public void init() {
		  super.setEntityManagerFactory(entityManagerFactory);
	}
	
   	@Override
	public Account AutenticarUsuario(Account account) {
		// TODO Auto-generated method stub
   		String abc ="";
   		System.out.println(abc);
   		//entityManager.cre
   		//this.entityManager.createQuery("")
   	 Map<String, String> params = new HashMap<String, String>();
     params.put("accountMail", account.getAcIdAccountPk());
     params.put("accountPwd", account.getAcStPassword());
     List<Account> findByNamedQueryAndNamedParams = this.getJpaTemplate().findByNamedQueryAndNamedParams("getUser", params);
		List<Account> lstAccount = findByNamedQueryAndNamedParams;
		if(lstAccount.size() >0)
   			return lstAccount.get(0);
   		else
   			return new Account();
   		
	}

}
